/*
 * I write in my free time, for personal using
 * when i fell proud of it, i will give it to public
 * now,have nothing more to say
 */
package com.quangtin3.trans;

import com.quangtin3.tunll.*;
import com.quangtin3.msg.Channel;
import com.quangtin3.msg.Msg;
import com.quangtin3.utils.ControlAble;
import com.quangtin3.utils.TunllException;
import com.quangtin3.utils.TunllLogger;

/**
 * receive message from other trans and queue to process
 * each object handle one and only one trans connection
 * @author quanghx
 */
public class TransReceiver implements Runnable, ControlAble {

    private Processor processor;
    private Channel channel;

    public TransReceiver(Processor parent, Channel channel) {
        this.processor = parent;
        this.channel = channel;
    }

    public void run() {
        //continue receive message and queue to processor
        try {
            TunllLogger.sys.info("thread started");
            while (true) {
                Msg job = channel.receive();
                TunllLogger.sys.debug("received " + job.toString());
                processor.queue(job);
            }
        } catch (TunllException e) {
            TunllLogger.sys.error("exception " + e.getMessage());
        }
    }

    /**
     * close channel associated with this object and
     * stop thread running it. release all resource
     */
    public void requestStop() {

    }

    public void requestSuspend() {

    }

    public void requestResume() {

    }

    public boolean isAlive() {
        return false;
    }
    
    public synchronized void requestStart() {
    }
}
